precision mediump float;

uniform sampler2D u_ObjSampler;
uniform vec3 u_CameraPosition;	//Camera position
varying vec3 v_VertPosition;
varying vec2 v_VertTexCoord;
varying vec3 v_VertNorm;

void main()
{
	vec4 cObj = texture2D(u_ObjSampler, v_VertTexCoord);
	vec4 cAmbientComponent = vec4(1.0, 1.0, 1.0, 1.0);
	vec3 vToEye = normalize(u_CameraPosition - v_VertPosition);
	vec3 vVertNorm = vec3(normalize(v_VertNorm));
	
	//First Lighting Source
	vec3 vLightDirection = normalize(v_VertPosition - vec3(50.0, 120.0,10.0));
	vec4 cDiffuseComponent = max(dot(vVertNorm, -vLightDirection), 0.0) * vec4(1.0, 1.0, 1.0, 1.0); //White light
	vec3 vReflect = normalize(reflect(vLightDirection, vVertNorm));
	vec4 cSpecularComponent = pow(max(dot(vReflect, vToEye), 0.0), 20.0) * vec4(1.0, 1.0, 1.0, 1.0); //While light
	
	//Second Lighting Source
	vec3 vLightDirectionSecond = normalize(v_VertPosition - vec3(-50.0, 120.0, 10.0));
	vec4 cDiffuseComponentSecond = max(dot(vVertNorm, -vLightDirectionSecond), 0.0) * vec4(1.0, 0.0, 0.0, 1.0);
	vec3 vReflectSecond = normalize(reflect(vLightDirectionSecond, vVertNorm));
	vec4 cSpecularComponentSecond = pow(max(dot(vReflectSecond, vToEye), 0.0), 20.0) * vec4(1.0, 1.0, 0.0, 1.0);
	
	float fWeight = 0.2;
	vec4 cFinal = vec4(((cAmbientComponent * fWeight + (cDiffuseComponent + cDiffuseComponentSecond) * (1.0 - fWeight)) * cObj + (cSpecularComponent + cSpecularComponentSecond)).xyz, cObj.w);
	
	gl_FragColor = cFinal;
}